

//后台系统apitoken生成
let jwt = require('jsonwebtoken');

 exports.createToken = async function (userName,userId,role) {
    let date = new Date().toString();
    let token = jwt.sign({ foo: userName,userId:userId,role:role}, date);
   return token;
    
 }


 // token 解析

 exports.decodeToken  = async function(req){
  let apiToken = req.headers.authorization;
  let decoded = jwt.decode(apiToken, {complete: true});
  let result =decoded.payload;
  return result;
 }